package com.fourth.controller.api;

import com.fourth.dao.SortDao;
import com.fourth.service.BusinessService;
import com.ljx.entity.BusinessInfo;
import com.ljx.entity.Sort;
import com.ljx.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiaoZhu
 * @version 1.0
 * @date 2023/3/3 20:15
 */
@Api(value = "commodity/UB/business", tags = {""})
@RestController
@RequestMapping("commodity/UB/business")
public class UBApiBusinessController {
    @Autowired
    private BusinessService businessService;
    @Autowired
    private SortDao sortDao;

    /**
     * 商户入驻申请
     * @param businessInfo
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "BusinessInfo", name = "businessInfo", value = "", required = true)
    })
    @ApiOperation(value = "商户入驻申请", notes = "商户入驻申请", httpMethod = "POST")
    @PostMapping("/add")
    private Result add(@RequestBody BusinessInfo businessInfo){
//        if(businessInfo.getSort()=="" || businessInfo.getIdcard()=="" || businessInfo.getSname()=="" || businessInfo.getBname()=="" || businessInfo.getTelephone()=="" || businessInfo.getAddress()==""){
//            return new Result(500,"申请失败");
//        }else {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        String encode = passwordEncoder.encode("123456");
        businessInfo.setPassword(encode);
        boolean b = businessService.save(businessInfo);
            if (b==true){
                return new Result(200,"申请成功");
            }
            return new Result(500,"申请失败");
//        }

    }

    /**
     * 查询商品类别
     * @return
     */
    @ApiOperation(value = "查询商品类别", notes = "查询商品类别", httpMethod = "GET")
    @GetMapping("sortSelect")
    public Result sortSelect(){
        List<Sort> list = sortDao.selectList(null);
        return new Result(200,"查询成功",list);
    }

    /**
     * 查询更多商户
     * @param zoneName
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "string", name = "zoneName", value = "", required = true)
    })
    @ApiOperation(value = "查询更多商户", notes = "查询更多商户", httpMethod = "GET")
    @GetMapping("/selectAllZoneBusiness")
    public Result selectAllZoneBusiness(String zoneName){
        System.out.println("zoneName = " + zoneName);
        return businessService.selectAllZoneBusiness(zoneName);

    }
}
